package com.gzgs.service.impl;

import com.gzgs.dao.OrdersDao;
import com.gzgs.dao.ProductDao;
import com.gzgs.domain.Product;
import com.gzgs.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 业务层金额口实现类
 */
@Service("productService")
@Transactional
public class ProductServiceImpl implements ProductService {

    @Autowired
    private ProductDao productDao;

    @Autowired
    private OrdersDao ordersDao;

    /**
     * 查询所有的账户
     * @return
     * @throws Exception
     */
    @Override
    public List<Product> findAll() throws Exception {
        return productDao.findAll();
    }

    @Override
    public Product findById(String id) throws Exception {
        return productDao.findById(id);
    }

    @Override
    public void saveProduct(Product product) throws Exception {
        productDao.saveProduct(product);
    }

    @Override
    public void deleteById(String id) throws Exception {
        productDao.deleteById(id);
        ordersDao.deleteByProductId(id);
    }
}
